package dht.data;

public class Options {
	public static final int dimensions=2;
	public static int socket_get_timeout=100;
	public static int socket_put_timeout=100;
	public static final int MAX_SOCKET_TIMEOUT=1000;
	public static final int MIN_SOCKET_TIMEOUT=5;
	public static int delta=50;
	
	/**
	 * Update the timeout
	 * @param enhance enhance the timeout if true
	 * @param decrease decrease the timeout if true
	 */
	public static void update_socketGetTimeout(boolean enhance, boolean decrease) {
		if (enhance) {
			socket_get_timeout=Math.min(socket_get_timeout+delta, MAX_SOCKET_TIMEOUT);
			if (delta>10) {
				delta=delta/2;
			} else {
				delta=1;
			}
			return;
		}
		if (decrease) {
			socket_get_timeout=Math.max(socket_get_timeout-delta, MIN_SOCKET_TIMEOUT);
			if (delta>10) {
				delta=delta/2;
			} else {
				delta=1;
			}
			return;
		}
	}
	
	/**
	 * Update the timeout
	 * @param enhance enhance the timeout if true
	 * @param decrease decrease the timeout if true
	 */
	public static void update_socketPutTimeout(boolean enhance, boolean decrease) {
		if (enhance) {
			socket_put_timeout=Math.min(socket_put_timeout+delta, MAX_SOCKET_TIMEOUT);
			if (delta>10) {
				delta=delta/2;
			}
			return;
		}
		if (decrease) {
			socket_put_timeout=Math.max(socket_put_timeout-delta, MIN_SOCKET_TIMEOUT);
			if (delta>10) {
				delta=delta/2;
			}
			return;
		}
	}
	
}
